package cn.iocoder.yudao.module.infra.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 暴露服务器静态资源
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {


    @Value("${yudao.file.upload-path}")
    private String materialFilePrePath;


    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        String fileUtl = "file:" + materialFilePrePath.replace("\\", "/");
        registry.addResourceHandler("/file/**").addResourceLocations(fileUtl).setCachePeriod(0);
        registry.addResourceHandler("/**").addResourceLocations("classpath:/META-INF/resources/").setCachePeriod(0);
    }
}